package com.xyd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xyd.dao.UserMapper;
import com.xyd.entity.User;
import com.xyd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page queryLikeUsers(Map<String, Object> cond) {
        Page page = new Page();
        //查询出总条数，赋给pageHelper的属性
        page.setTotal(userMapper.getLikeUsersCount(cond));
        //从cond中获得每页条数pageSize和当前页pageNum
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        int pageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(pageNum);
        page = PageHelper.startPage(pageNum, pageSize);
        List list = userMapper.getLikeUsers(cond);
        System.out.println(list.size());
        return page;
    }

    @Override
    public Integer addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public Integer delUser(User user) {
        return userMapper.delUser(user);
    }

    @Override
    public User getUserById(User user) {
        return userMapper.getUserById(user);
    }

    @Override
    public Integer updateUser(User user) {
        return userMapper.updateUser(user);
    }
}
